<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

require_once(dirname(__FILE__) . "/../common/Logger.php");
require_once(dirname(__FILE__) . "/../common/Common.php");
require_once(dirname(__FILE__) . "/../dbcom/WeiXinCom.php");
require_once(dirname(__FILE__) . "/../dbcom/CustomerCom.php");
require_once(dirname(__FILE__) . "/../dbcom/WorkerCom.php");

$log = new Logger("./../wloginapi.log");
$common = new Common();
$weixincom = new WeiXinCom();
$customercom = new CustomerCom();
$workercom = new WorkerCom();

if((!isset($_REQUEST['account'])||empty($_REQUEST['account']))||(!isset($_REQUEST['password'])|empty($_REQUEST['password']))){
    echo json_encode(array("code" => 100, "msg" => "cannot request logininfo"));
    exit();
}

$account = $_REQUEST['account'];
$password = $_REQUEST['password'];

$myinfo = $workercom->getPassword($account);
if(!$myinfo){
    echo json_encode(array("code" => 400, "msg" => "cannot find user"));
    exit();
}

$password1 = md5($password);
if($password1 == $myinfo['password']){
    echo json_encode(array("code" => 0, "msg" => "success","data"=>array("userid"=>$myinfo['id'])));
}else{
    echo json_encode(array("code" => 50, "msg" => "error password"));
}

exit();